<template>
	<view class="wallet-container">
		<!-- 背景元素 -->
		<view class="wallet-bg">
			<view class="bg-grid"></view>
			<view class="bg-glow"></view>
		</view>
		
		<!-- 主要内容 -->
		<view class="wallet-content">
			<!-- 用户余额卡片 -->
			<view class="wallet-card">
				<view class="card-header">
					<text class="card-title">当前余额</text>
					<view class="card-decoration"></view>
				</view>
				<view class="balance-display">
					<text class="currency-symbol">$</text>
					<text class="balance-amount">{{userinfo.money || '0.00'}}</text>
				</view>
				<view class="action-buttons">
					<navigator url="/pages/client/vipcard/recharge" class="action-button recharge-button">
						<text class="button-icon">+</text>
						<text class="button-text">充值</text>
					</navigator>
					<navigator v-if="userinfo.zstx > 0" url="/pages/client/member/tx" class="action-button withdraw-button">
						<text class="button-icon">⇧</text>
						<text class="button-text">提现</text>
					</navigator>
				</view>
				<view class="card-footer">
					<text class="footer-text">最后更新: {{new Date().toLocaleString()}}</text>
				</view>
			</view>
			
			<!-- 交易记录列表 -->
			<view class="transaction-header">
				<text class="header-title">交易记录</text>
				<view class="header-line"></view>
			</view>
			
			<view class="transaction-list">
				<block v-for="(item,index) in listData" :key="index">
					<view class="transaction-item">
						<view class="item-left">
							<view class="item-type" :class="{'income': item.jzt === '+', 'expense': item.jzt === '-'}">
								{{item.jzt === '+' ? '收入' : '支出'}}
							</view>
							<view class="item-details">
								<text class="item-memo">{{item.memo}}</text>
								<text class="item-date">{{item.createtime}}</text>
							</view>
						</view>
						<view class="item-amount" :class="{'income-amount': item.jzt === '+', 'expense-amount': item.jzt === '-'}">
							{{item.jzt}}{{item.money}}
						</view>
					</view>
				</block>
			</view>
			
			<uni-load-more :status="status" :content-text="contentText" />
		</view>
	</view>
</template>

<script>
	import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
	export default {
		components: {
			uniLoadMore
		},
		data(){
			return {
				listData: [],
				last_id: 0,
				reload: true,
				status: 'more',
				userinfo:[],
				contentText: {
					contentdown: '上拉加载更多',
					contentrefresh: '加载中',
					contentnomore: '没有更多记录了'
				}
			}
		},
		onReachBottom() {
			this.status = 'more';
			this.getList();
		},
		onLoad() {
			this.getUserInfo();
			this.getList();
		},
		onShow() {
			this.getUserInfo();
		},
		methods:{
			// 获取用户信息
			getUserInfo() {
				let data = {};
				data.token = uni.getStorageSync("userinfo").token;
				data.uid = uni.getStorageSync("userinfo").token ? uni.getStorageSync("userinfo").id : 0;
				
				if (!data.token) {
					return;
				}
				
				uni.request({
					url: this.configs.webUrl+'/api/user/index',
					data: data,
					success: res => {
						if (res.data.code == 1) {
							let userInfo = res.data.data;
							userInfo.isLogin = true;
							this.userinfo = userInfo;
							uni.setStorage({
								key: 'userinfo',
								data: res.data.data
							});
						}
					},
					fail: (data, code) => {
						console.log('获取用户信息失败');
					}
				});
			},
			
			getList() {
				let data = {};
				var limit=10;
				if (this.last_id>0) {
					//说明已有数据，目前处于上拉加载
					this.status = 'loading';
					data.offset = this.last_id*limit;
					data._ = new Date().getTime() + '';
				}
				data.limit=limit		
				data.token = uni.getStorageSync("userinfo").token;
				uni.request({
					url: this.configs.webUrl+'/api/user/usermoneyinfo',
					data: data,
					success: data => {
						console.log(data.data)
						if (data.data.total>0) {
							let list = data.data.rows;
							this.listData = this.reload ? list : this.listData.concat(list);
							this.reload = false;
							this.last_id = this.last_id+1;
							if(data.data.total<this.last_id*limit){
								this.status = '';
							}
						}else{
							this.contentText.contentdown='没有数据'
						}
					},
					fail: (data, code) => {
						//console.log('fail' + JSON.stringify(data));
					}
				});
			},
		}
	}
</script>

<style>
	/* 基础样式 */
	page {
		background: transparent;
	}
	
	/* 钱包容器 */
	.wallet-container {
		position: relative;
		width: 100%;
		min-height: 100vh;
	}
	
	/* 背景元素 */
	.wallet-bg {
		position: fixed;
		top: 0;
		left: 0;
		width: 100%;
		height: 100%;
		background: linear-gradient(135deg, #0a0a0a 0%, #1a1a1a 100%);
		z-index: -1;
		overflow: hidden;
	}
	
	.bg-grid {
		position: absolute;
		width: 100%;
		height: 100%;
		background-image: 
			linear-gradient(rgba(255, 204, 0, 0.05) 1px, transparent 1px),
			linear-gradient(90deg, rgba(255, 204, 0, 0.05) 1px, transparent 1px);
		background-size: 40px 40px;
		opacity: 0.5;
	}
	
	.bg-glow {
		position: absolute;
		width: 300%;
		height: 300%;
		top: -100%;
		left: -100%;
		background: radial-gradient(circle, rgba(255, 204, 0, 0.05) 0%, transparent 70%);
		animation: rotate-glow 60s linear infinite;
	}
	
	@keyframes rotate-glow {
		0% { transform: rotate(0deg); }
		100% { transform: rotate(360deg); }
	}
	
	/* 主要内容 */
	.wallet-content {
		padding: 30rpx;
		position: relative;
		z-index: 1;
	}
	
	/* 钱包卡片 */
	.wallet-card {
		background: linear-gradient(145deg, #1a1a1a, #0d0d0d);
		border-radius: 24rpx;
		padding: 40rpx 30rpx;
		margin-bottom: 40rpx;
		box-shadow: 0 10rpx 40rpx rgba(0, 0, 0, 0.5);
		border: 1px solid rgba(255, 204, 0, 0.2);
		position: relative;
		overflow: hidden;
	}
	
	.wallet-card::before {
		content: '';
		position: absolute;
		top: 0;
		left: 0;
		width: 100%;
		height: 8rpx;
		background: linear-gradient(90deg, #ffcc00, #ff9900);
	}
	
	.card-header {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-bottom: 30rpx;
	}
	
	.card-title {
		font-size: 32rpx;
		font-weight: 600;
		color: rgba(255, 255, 255, 0.9);
	}
	
	.card-decoration {
		width: 60rpx;
		height: 4rpx;
		background: linear-gradient(90deg, #ffcc00, #ff9900);
		border-radius: 2rpx;
	}
	
	/* 余额显示 */
	.balance-display {
		display: flex;
		align-items: baseline;
		margin-bottom: 40rpx;
	}
	
	.currency-symbol {
		font-size: 36rpx;
		font-weight: 600;
		color: #ffcc00;
		margin-right: 10rpx;
	}
	
	.balance-amount {
		font-size: 72rpx;
		font-weight: 700;
		color: #ffffff;
		line-height: 1;
		text-shadow: 0 0 20rpx rgba(255, 204, 0, 0.3);
	}
	
	/* 操作按钮 */
	.action-buttons {
		display: flex;
		gap: 20rpx;
		margin-bottom: 30rpx;
	}
	
	.action-button {
		flex: 1;
		height: 80rpx;
		border-radius: 40rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		font-weight: 600;
		transition: all 0.3s;
		position: relative;
		overflow: hidden;
	}
	
	.action-button:active {
		transform: scale(0.95);
	}
	
	.recharge-button {
		background: linear-gradient(90deg, #ffcc00, #ff9900);
		color: #000000;
		box-shadow: 0 8rpx 24rpx rgba(255, 204, 0, 0.3);
	}
	
	.withdraw-button {
		background: rgba(30, 30, 30, 0.8);
		color: #ffcc00;
		border: 1px solid rgba(255, 204, 0, 0.5);
		box-shadow: 0 8rpx 24rpx rgba(0, 0, 0, 0.3);
	}
	
	.button-icon {
		margin-right: 10rpx;
		font-weight: bold;
	}
	
	.button-text {
		font-size: 28rpx;
	}
	
	.card-footer {
		text-align: right;
	}
	
	.footer-text {
		font-size: 24rpx;
		color: rgba(255, 255, 255, 0.5);
	}
	
	/* 交易记录 */
	.transaction-header {
		display: flex;
		align-items: center;
		margin-bottom: 30rpx;
	}
	
	.header-title {
		font-size: 32rpx;
		font-weight: 600;
		color: #ffffff;
		padding-right: 20rpx;
	}
	
	.header-line {
		flex: 1;
		height: 2rpx;
		background: linear-gradient(90deg, rgba(255, 204, 0, 0.5), transparent);
	}
	
	/* 交易列表 */
	.transaction-list {
		margin-bottom: 40rpx;
	}
	
	.transaction-item {
		background: rgba(30, 30, 30, 0.7);
		border-radius: 16rpx;
		padding: 28rpx 24rpx;
		margin-bottom: 20rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		border: 1px solid rgba(255, 204, 0, 0.1);
		transition: all 0.3s;
	}
	
	.transaction-item:active {
		transform: scale(0.98);
		background: rgba(40, 40, 40, 0.7);
	}
	
	.item-left {
		display: flex;
		align-items: center;
	}
	
	.item-type {
		width: 80rpx;
		height: 40rpx;
		border-radius: 8rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 22rpx;
		font-weight: 600;
		margin-right: 20rpx;
	}
	
	.income {
		background: rgba(0, 200, 83, 0.2);
		color: #00c853;
	}
	
	.expense {
		background: rgba(255, 64, 64, 0.2);
		color: #ff4040;
	}
	
	.item-details {
		display: flex;
		flex-direction: column;
	}
	
	.item-memo {
		font-size: 28rpx;
		color: #ffffff;
		margin-bottom: 8rpx;
	}
	
	.item-date {
		font-size: 24rpx;
		color: rgba(255, 255, 255, 0.6);
	}
	
	.item-amount {
		font-size: 32rpx;
		font-weight: 700;
	}
	
	.income-amount {
		color: #00c853;
	}
	
	.expense-amount {
		color: #ff4040;
	}
	
	/* 加载更多 */
	.uni-load-more {
		margin-top: 40rpx;
		color: rgba(255, 255, 255, 0.7) !important;
	}

	.wallet-container{
		background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
	}
</style>